/**
 * SA扫描管理模块类型定义
 */

// ==================== 通用类型 ====================

/**
 * API响应格式
 */
export interface ApiResponse<T = any> {
    code: number;
    message: string;
    data: T;
}

/**
 * 分页结果
 */
export interface PageResult<T> {
    total: number;
    list: T[];
    pageNum: number;
    pageSize: number;
}

/**
 * 基础查询参数
 */
export interface BaseQueryParams {
    unitId?: string;
    startTime?: string;
    endTime?: string;
    pageNum: number;
    pageSize: number;
}

// ==================== SA扫描日志 ====================

/**
 * SA扫描日志实体
 */
export interface SaScanLog {
    id: number;
    unitId: string;
    ip: string;
    processKey: string;
    scanTime: string;
    methodCount: number;
    scanDurationMs: number;
    success: boolean;
    result: string;
    createTime?: string;
    updateTime?: string;
}

/**
 * SA扫描日志查询参数
 */
export interface SaScanLogQueryParams extends BaseQueryParams {
    success?: boolean;
}

// ==================== SA扫描记录 ====================

/**
 * SA扫描记录实体
 */
export interface SaReportRecord {
    id: number;
    appId: string;
    unitId: string;
    scanResult: string;
    recordCount: number;
    fileName: string;
    ip: string;
    scanDate: string;
    createTime?: string;
    updateTime?: string;
}

/**
 * SA扫描记录查询参数
 */
export interface SaReportRecordQueryParams extends BaseQueryParams {
    // 扫描记录只需要基础查询参数
}

// ==================== SA部署日志 ====================

/**
 * SA部署日志实体
 */
export interface SaScanDeployLog {
    id: number;
    unitId: string;
    deployTime: string;
    isSuccess: boolean;
    isReplace: boolean;
    javaVersion: string;
    result: string;
    createTime?: string;
    updateTime?: string;
}

/**
 * SA部署日志查询参数
 */
export interface SaScanDeployLogQueryParams extends BaseQueryParams {
    isSuccess?: boolean;
}

// ==================== SA分析任务 ====================

/**
 * 触发类型枚举
 */
export enum TriggerType {
    MANUAL = 'MANUAL',
    SCHEDULE = 'SCHEDULE',
    UNIT = 'UNIT',
    AUTO = 'AUTO'
}

/**
 * 任务状态枚举
 */
export enum TaskStatus {
    RUNNING = 'RUNNING',
    SUCCESS = 'SUCCESS',
    FAILED = 'FAILED',
    PENDING = 'PENDING'
}

/**
 * SA分析任务实体
 */
export interface SaReportAnaTask {
    id: number;
    unitId: string;
    startTime: string;
    endTime: string;
    triggerType: TriggerType;
    scanRecordCount: number;
    scanDurationMs: number;
    scanResult: string;
    taskStatus: TaskStatus;
    createTime?: string;
    updateTime?: string;
}

/**
 * SA分析任务查询参数
 */
export interface SaReportAnaTaskQueryParams extends BaseQueryParams {
    triggerType?: TriggerType;
    taskStatus?: TaskStatus;
}

// ==================== 枚举映射 ====================

/**
 * 触发类型标签映射
 */
export const TRIGGER_TYPE_LABELS: Record<TriggerType, string> = {
    [TriggerType.MANUAL]: '手动触发',
    [TriggerType.SCHEDULE]: '定时触发',
    [TriggerType.UNIT]: '单元触发',
    [TriggerType.AUTO]: '自动触发'
};

/**
 * 任务状态标签映射
 */
export const TASK_STATUS_LABELS: Record<TaskStatus, string> = {
    [TaskStatus.RUNNING]: '运行中',
    [TaskStatus.SUCCESS]: '成功',
    [TaskStatus.FAILED]: '失败',
    [TaskStatus.PENDING]: '待执行'
};

/**
 * 任务状态颜色映射
 */
export const TASK_STATUS_COLORS: Record<TaskStatus, string> = {
    [TaskStatus.RUNNING]: 'processing',
    [TaskStatus.SUCCESS]: 'success',
    [TaskStatus.FAILED]: 'error',
    [TaskStatus.PENDING]: 'default'
};

// ==================== Tab类型 ====================

/**
 * Tab键值
 */
export type TabKey = 'scanLog' | 'reportRecord' | 'deployLog' | 'anaTask';

/**
 * Tab间传递的参数
 */
export interface TabNavigationParams {
    targetTab: TabKey;
    unitId?: string;
}
